<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\admin\model\Member;
use app\admin\model\User;
use think\Session;
class Login extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    protected $beforeActionList = [

        'loginvc' =>  ['except'=>'loginout'],

    ];
    public function loginvc()
    {
        $result=Session::has('user_id');
        if($result){
            $this->success('用户已经登录', 'index/index');
        }
    }


    public function index()
    {
//return json([
//   'login'=>false
//]);
        return $this->fetch('login/login');
    }
    public function logining(Request $request){

        if( input('param.username')){


            $user=User::get(['name'=>  input('param.username')]);
            if (input('param.password')===$user['password']){
                $userinfo=$user->profile;
                Session::set('user_id',$userinfo);
               return json([
                   'code'=>200,
                   'msg'=>'登陆成功'
               ]);
            } else {
                return json([
                    'code'=>0,
                    'msg'=>'登录失败'
                ]);
            }
        }else{
            return json([

                'msg'=>'跳转错误'
            ]);
        }
    }
    public function loginout()
    {
        Session::clear('');
        $result=Session::has('user_id');
        if(!$result){
            $this->success('退出成功', 'login/index');
        }else{
            $this->error('退出失败', 'index/index');
        }
    }
}